package com.weiyuwqj.server.service.sys.impl;

import com.github.pagehelper.PageHelper;
import com.weiyuwqj.server.service.base.BaseServiceImpl;
import com.weiyuwqj.api.constant.Global;
import com.weiyuwqj.api.service.SysNoticeTypeService;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.server.mapper.SysNoticeTypeMapper;
import com.weiyuwqj.api.model.SysNoticeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by zhangxiaojian on 15/10/13.
 */
@Service("noticeTypeService")
public class SysNoticeTypeServiceImpl extends BaseServiceImpl<SysNoticeType> implements SysNoticeTypeService {

    @Autowired
    SysNoticeTypeMapper sysNoticeTypeMapper;

    //显示-分页
    @Override
//    public List<Map<String, Object>> getList(Paginator p) {
//        PageHelper.startPage(p.getPageNum(), p.getPageSize());
//        List<Map<String,Object>> list = sysNoticeTypeMapper.getList();
//        return list;
//    }
    public PageList getList(Paginator p, Map<String, Object> param) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        List<SysNoticeType> list = sysNoticeTypeMapper.getList(param);
        return new PageList(list);
    }

    //新建模板
    @Override
    public void add(SysNoticeType sysNoticeType) {
        sysNoticeTypeMapper.insert(sysNoticeType);
    }

    //获取编辑信息
    @Override
    public SysNoticeType getSingle(Integer id) {
        return sysNoticeTypeMapper.getSingle(id);
    }

    @Override
    public SysNoticeType getNoticeTypeByNid(String nid) {
        return sysNoticeTypeMapper.getNoticeTypeByNid(nid);
    }

    //启用禁用
    @Override
    public void enableToggle(int noticeId) {
        SysNoticeType notice = this.selectByKey(noticeId);
        int newStatus = 0;
        if (notice.getStatus() == 1) {
            newStatus = 0;
        } else {
            newStatus = 1;
        }
        sysNoticeTypeMapper.updateUserStatus(newStatus, noticeId);
    }

    @Override
    public String getMobile() {
        return Global.getAuthorizationMobile();
    }

}
